<div id="debtsPage">
    <div class="post">
        <h2 class="title">Debts</h2>
        <div class="entry">
            <script>
                $(function() {
                    $( "#debt_datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
                });
            </script>
            <script>
                $(function() {
                    $( "#debt_datepicker2" ).datepicker({ dateFormat: 'yy-mm-dd' });
                });
            </script>

            <input type="button" value="Add new" onclick="show('#new_debt')"/>

            <?php
         //   if ($this->session->userdata("admin")) {
            ?>
                <input type="button" value="Search" onclick="show('#searchDebts')"/>
                <input type="button" value="Clear Search" onclick="clearSearch()"/>
            <?php
         //   }
            ?>

            <div id="debt_result" class="info">
                <?= $message ?>
            </div>
            <script type="text/javascript">
                function searchDebts(num){
                    field=document.getElementById("searchDebtsForm"+num).field.value;
                    search=document.getElementById("searchDebtsForm"+num).search.value;
                    $("#debtsPage").load("<?= base_url(); ?>index.php?/admin_mis/debts/"+field+"/"+search);
                }
                function clearSearch(){
                    $("#debtsPage").load("<?= base_url(); ?>index.php?/admin_mis/debts/");
                }
            </script>

            <!--a href="" id="hide3" >Hide</a> <a href="" id="show3" >Show</a-->
            <div id="new_debt" style="display: none;margin-bottom: 10px;">
                <?php $data['id'] = "debt_form" ?>
                <?= form_open_multipart('mis/saveDebt', $data); ?>
                <table>
                    <tr class="lighter"><td class="half">Department</td><td>
                            <select name="department">
                                <?php foreach ($sbus as $type): ?>
                                    <option value="<?= $type->tid; ?>"><?= $type->name; ?></option>
                                <?php endforeach; ?>
                                </select>
                            </td> </tr>
                        <tr class="darker"><td class="half">Debtor's Name</td><td><input type="text" class="wide" name="debtor" value="<?php echo set_value('debtor'); ?>"  /></td> </tr>
                        <tr class="lighter"><td>Transaction Date</td><td><input type="text" class="wide"  name="debt_date" value="<?php echo set_value('debt_date'); ?>"  id="debt_datepicker" /></td> </tr>
                        <tr  class="darker"><td>Debt Description</td><td><input type="text"  class="wide" name="debt_description" value="<?php echo set_value('debt_description'); ?>" /></td> </tr>
                        <tr  class="lighter"><td>Amount paid(Ksh)</td><td><input type="text"  class="wide" name="amount_paid" value="<?php echo set_value('amount'); ?>" /></td> </tr>
                        <tr  class="darker"><td>Amount due(Ksh)</td><td><input type="text"  class="wide" name="amount" value="<?php echo set_value('amount'); ?>" /></td> </tr>
                        <tr class="lighter"><td>Date due</td><td><input type="text" class="wide"  name="due_date" value="<?php echo set_value('due_date'); ?>" id="debt_datepicker2"  /></td> </tr>
                        <tr class="darker"><td>Relationship manager</td><td><input type="text" class="wide"  name="relationship_manager" value="<?php echo set_value('relationship_manager'); ?>"  /></td> </tr>
                        <tr><td colspan="2" style="text-align: right">
                                <input type="submit" value="Submit" />
                                <input type="button" value="Cancel" onclick="hide('#new_debt')"/>
                            </td></tr>
                    </table>
                    </form>
                </div>
                <div id="searchDebts" style="display: none;margin-bottom: 10px;">
                    <form id="searchDebtsForm1">
                        <input type="hidden" name="field" value="department"/>
                        <table>
                            <tr class="darker"><td class="half">Search by SBU</td>
                                <td><select name="search">
                                    <?php foreach ($sbus as $type): ?>
                                        <option value="<?= $type->tid; ?>"><?= $type->name; ?></option>
                                    <?php endforeach; ?>
                                    </select></td>
                                 </tr>

                            <tr><td colspan="2" style="text-align: right">
                                    <input type="button" value="Submit" onclick="searchDebts(1)" />
                                    <input type="button" value="Cancel" onclick="hide('#searchDebts')"/>
                                </td></tr>

                        </table>
                    </form>
                    <form id="searchDebtsForm2">
                        <table>
                            <tr class="darker"><td class="half">Select search criteria</td>
                                <td><select name="field">
                                        <option value='all' >All</option>
                                        <option value='debtor' >Debtor</option>
                                        <option value='debt_description'>Debt description</option>
                                        <option value='relationship_manager'>Relationship manager</option>
                                        <option value='added_by'> Added by</option>
                                    </select></td>
                                <td><input type="text" name="search" class="wide"  value="<?php echo set_value('added_by'); ?>" /></td>
                            </tr>

                            <tr><td colspan="3" style="text-align: right">
                                    <input type="button" value="Submit" onclick="searchDebts(2)" />
                                    <input type="button" value="Cancel" onclick="hide('#searchDebts')"/>
                                </td></tr>

                        </table>
                    </form>
                </div>
                <div id="all_debt">
                <?= $tablet ?>
                <?= $pagina ?>
            </div>

        </div>
    </div>